<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>二叉树-用JavaScript实现</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    body {
      background: #f0f0f0;
    }

    p {
      line-height: 25px;
      padding: 15px 20px;
    }
  </style>
</head>

<body>
  <div id="App" style="padding: 25px;">
    <h1>请按F12 打开开发者工具看效果</h1>
    <p>用调试工具打断点看效果，生成的二叉树结构如图：</p>
    <p>
      <img src="./assets/images/二叉树解释图.png" </p>
  </div>
  <script src="./assets/js/binary-tree.js" type="text/javascript"></script>
  <script type="text/javascript">
    let nodes = [8, 3, 10, 1, 6, 14, 4, 7, 13];
    let binaryTree = new BinaryTree();
    nodes.forEach(key => {
      binaryTree.insert(key);
    })
    let callback = function (key) {
      console.log(key)
    }
    console.log('----------------中序遍历 Start------------------------------')
    binaryTree.inOrderTraverse(callback);
    console.log('----------------左-根-右 End------------------------------')
    console.log('----------------前序遍历 Start------------------------------')
    binaryTree.preOrderTraverse(callback);
    console.log('----------------根-左-右 End------------------------------')
    console.log('----------------后序遍历 Start------------------------------')
    binaryTree.afterOrderTraverse(callback);
    console.log('----------------左-右-根 End------------------------------')
    console.log('----------------获取最小值 Start------------------------------')
    console.log(binaryTree.min())
    console.log('----------------获取最小值 End------------------------------')
    console.log('----------------获取最大值 Start------------------------------')
    console.log(binaryTree.max())
    console.log('----------------获取最大值 End------------------------------')
    console.log('----------------查找二叉树 Start------------------------------')
    console.log(binaryTree.search(7))
    console.log('----------------查找二叉树 End------------------------------')
    console.log('----------------删除二叉树 Start------------------------------')
    console.log(binaryTree.remove(13))
    console.log('----------------删除二叉树 End------------------------------')
  </script>
</body>

</html>